{extend name="extra@admin/content"}

{block name="content"}
    <!--<span style="background: green;" onclick="change(1);">基本信息</span>-->
    <!--<span style="background: green;" onclick="change(2);">图集</span>-->
    <!--<span style="background: green;" onclick="change(3);">库存</span>-->
<form onsubmit="return false;" action="__SELF__" data-auto="true" method="post" class='layui-form' style='padding-top:20px'>
    <div class="layui-form-item">
        <label class="layui-form-label">商品名称</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.name)}
            <input name="name" value='{$vo.name|default=""}'
                   required="required" title="请输入商品名称" maxlength="50" placeholder="请输入商品名称" class="layui-input ">
            {else}
            <input name="name" value='{$vo.name|default=""}' maxlength="50" required="required"
                   title="请输入商品名称称" class="layui-input">
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">副标题</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.subtitle)}
            <input name="subtitle" value='{$vo.subtitle|default=""}'
                   required="required" title="请输入副标题" maxlength="20" placeholder="请输入副标题" class="layui-input ">
            {else}
            <input name="subtitle" value='{$vo.subtitle|default=""}' maxlength="20" required="required"
                   title="请输入商品名称称" class="layui-input">
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品货号</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.good_number)}
            <input name="good_number" value='{$vo.good_number|default=""}'
                   required="required" title="请输入商品货号" maxlength="50" lay-verify="number" placeholder="请输入商品货号" class="layui-input ">
            {else}
            <input name="good_number" value='{$vo.good_number|default=""}' maxlength="50" lay-verify="number" required="required"
                   title="请输入商品名称称" class="layui-input">
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">基本规格</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.base_spec)}
            <input name="base_spec" value='{$vo.base_spec|default=""}'
                   required="required" title="请输入商品基本规格" placeholder="请输入商品基本规格" class="layui-input ">
            {else}
            <input name="base_spec" value='{$vo.base_spec|default=""}' required="required"
                   title="请输入商品基本规格" class="layui-input">
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">单位</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.unit)}
            <input name="unit" value='{$vo.unit|default=""}'
                   required="required" title="请输入商品单位" placeholder="请输入商品单位" class="layui-input ">
            {else}
            <input name="unit" value='{$vo.unit|default=""}' required="required"
                   title="请输入商品单位" class="layui-input">
            {/if}
        </div>
    </div>
    <!-- <div class="layui-form-item">
        <label class="layui-form-label">商品积分</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.score)}
            <input type="number" name="score" value='{$vo.score|default=""}'
                   required="required" title="请输入商品积分" placeholder="请输入商品积分" class="layui-input ">
            {else}
            <input type="number" name="score" value='{$vo.score|default=""}' required="required"
                   title="请输入商品积分" class="layui-input">
            {/if}
        </div>
    </div> -->
    <div class="layui-form-item">
        <label class="layui-form-label">商品分类</label>
        <div class="layui-input-block">
            <select name="cat_id" lay-verify="required" lay-filter="test" lay-search>
                <option value="">请选择商品分类</option>
                {volist name='category' id='v'}
                <option value="{$v.id}" >{$v.title}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">扩展分类</label>
        <div class="layui-input-block">
            <select name="exp_cat" lay-verify="required" lay-filter="test" lay-search>
                <option value="">请选择扩展分类</option>
                {volist name='exp_category' id='v'}
                <option value="{$v.id}" >{$v.title}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">默认库存</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.price)}
            <input name="stock" value='{$vo.stock|default=""}'
                   required="required" title="请输入默认库存" placeholder="请输入默认库存" class="layui-input ">
            {else}
            <input name="stock" value='{$vo.stock|default=""}' required="required"
                   title="请输入默认库存" class="layui-input">
            {/if}
        </div>
    </div>
    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">价格价</label>-->
        <!--<div class="layui-input-block">-->
            <!--{if $vo and isset($vo.price)}-->
            <!--<input name="price" value='{$vo.price|default=""}'-->
                   <!--required="required" title="请输入市场价" placeholder="请输入市场价" class="layui-input ">-->
            <!--{else /}-->
            <!--<input name="price" value='{$vo.price|default=""}'-->
                   <!--required="required" title="请输入市场价" placeholder="请输入市场价" class="layui-input ">-->
            <!--{/if}-->
        <!--</div>-->
    <!--</div>-->
    <div class="layui-form-item">
        <label class="layui-form-label">商品价格</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.price)}
            <input name="price" value='{$vo.price|default=""}'
                   required="required" title="请输入商品价格" placeholder="请输入商品价格" class="layui-input ">
            {else}
            <input name="price" value='{$vo.price|default=""}' required="required"
                   title="请输入商品价格" class="layui-input">
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">会员价格</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.price)}
            <input name="member_price" value='{$vo.member_price|default=""}'
                    title="请输入会员价格" placeholder="请输入会员价格" class="layui-input ">
            注：仅是会员商品的是时候显示
            {else}
            <input name="member_price" value='{$vo.member_price|default=""}'
                   title="请输入商品价格" class="layui-input">
            <p style="color:red;">注：仅是会员商品的是时候显示</p>
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品类型</label>
        <div class="layui-input-block">
            {foreach name="level" item="v"}
                <input type="radio"  name="member_level_id" value="{$v.code}" title="{$v.title}">
            {/foreach}
            <p style="color:red;">注：若是会员商品，请选择对应的会员类型；否则请选择普通会员商品</p>
        </div>
    </div>
    <!-- <div class="layui-form-item">
        <label class="layui-form-label">允许自购</label>
        <div class="layui-input-block">
            <input type="radio"  name="is_zigou" value="0"  title="不允许" checked>
            <input type="radio"  name="is_zigou" value="1"  title="允许" >
        </div>
    </div> -->

    <div class="layui-form-item">
        <label class="layui-form-label">是否线上</label>
        <div class="layui-input-block">
            <input type="radio"  name="is_online" value="1"  title="允许" checked>
            <input type="radio"  name="is_online" value="0"  title="不允许" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否上架</label>
        <div class="layui-input-block">
            <input type="radio"  name="status" value="1"  title="上架" checked>
            <input type="radio"  name="status" value="0"  title="下架" >
        </div>
    </div>
    <!-- <div class="layui-form-item">
        <label class="layui-form-label">库存状态</label>
        <div class="layui-input-block">
            <input type="radio"  name="is_stock" value="1"  title="有库存" >
            <input type="radio"  name="is_stock" value="0"  title="无库存" >
            <input type="text" readonly="readonly" name="message" value='选择该商品是否是库存商品' required="required" 
                   title=""  class="layui-input" style="color:red;border: 0px;">
        </div>
    </div> -->
    <!-- <div class="layui-form-item">
        <label class="layui-form-label">商品规格</label>
            <div class="layui-input-block">
                <select name="goods_spec" lay-verify="required" lay-search>
                    <option value="">请选择商品规格</option>
                    {volist name='spec' id='v1'}
                    <option value="{$v1.id}">{$v1.name}</option>
                    {/volist}
                </select>
            </div>
    </div> -->
    <!-- <div class="layui-form-item" id="add">
        <div class="layui-inline">
            <label class="layui-form-label">添加属性</label>
        <input type="button" lay-filter="add" onclick="tianjia();" value="+" ></button>
        </div>
    </div> -->
    <div class="layui-form-item">
        <label class="layui-form-label">口味</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.taste)}
            <input name="taste" value='{$vo.taste|default=""}'
                   required="required" title="请输入口味" maxlength="50" placeholder="请输入口味" class="layui-input ">
            {else}
            <input name="taste" value='{$vo.taste|default=""}' maxlength="50" required="required"
                   title="请输入口味" class="layui-input">
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">保存方法</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.taste)}
            <input name="save_method" value='{$vo.save_method|default=""}'
                   required="required" title="请输入保存方法" maxlength="50" placeholder="请输入保存方法" class="layui-input ">
            {else}
            <input name="save_method" value='{$vo.save_method|default=""}' maxlength="50" required="required"
                   title="请输入保存方法" class="layui-input">
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">食用方法</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.taste)}
            <input name="eat_num" value='{$vo.eat_num|default=""}'
                   required="required" title="请输入推荐食用人数" maxlength="50" placeholder="请输入推荐食用人数" class="layui-input ">
            {else}
            <input name="eat_num" value='{$vo.eat_num|default=""}' maxlength="50" required="required"
                   title="请输入推荐食用人数" class="layui-input">
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品简介</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入商品简介不超过100个字符" maxlength="200" title="请输入商品简介" required="required" class="layui-textarea" name="description">{$vo.description|default=""}</textarea>
        </div>
    </div>
    <!--商品 logo-->
    <div class="layui-form-item">
        <label class="layui-form-label">展示图片*</label>
            <div class="uploadimage" style="margin-left:1%;">
                <input type="hidden"  name="logo" value="" />
            </div>
            <a data-file="one" data-field="logo" data-type="png,jpg,jpeg" data-uptype="qiniu" href="javascript:void(0)"
               class="uploadbutton"><i style="font-size:30px;" class="fa fa-upload" title="点击上传"></i></a>
            <script>
                require(['jquery'], function () {
                    $('[name="logo"]').on('change', function () {
                        $(this).parent().attr('data-tips-image', this.value).css('backgroundImage', 'url(' + this.value + ')');
                    });
                });
            </script>
    </div>
    <!--商品 logo-->
    <!--商品 轮播图-->
    <div class="layui-form-item">
        <label class="layui-form-label">轮播图 *</label>
        <style>
            .upload-option-button {
                float: right;
                background: rgba(0, 0, 0, 0.5);
                color: #fff;
                width: 20px;
                height: 20px;
                line-height: 20px;
                text-align: center;
                display: none
            }

            .upload-option-button:hover {
                text-decoration: none;
                color: #fff
            }

            .uploadimagemtl:hover a {
                display: inline-block
            }
        </style>

        <input type='hidden' name='images' value=""/>

        <a data-file="mut" data-field="images" data-type="png,jpg,jpeg" data-uptype="qiniu" href="javascript:void(0)" style="margin-left:1%;"><i style="font-size:30px;" class="fa fa-upload" title="点击上传"></i></a>

        <script type="text/javascript">
            require(['jquery'], function () {
                var tpl = '<div class="uploadimage transition uploadimagemtl"><a href="javascript:void(0)" class="layui-icon upload-option-button">&#x1006;</a></div>';
                $('[name="images"]').on('change', function () {
                    var input = this, values = [], srcs = this.value.split('|');
                    $(this).prevAll('.uploadimage').map(function () {
                        values.push($(this).attr('data-tips-image'));
                    }), $(this).prevAll('.uploadimage').remove();
                    values.reverse();
                    for (var i in srcs) {
                        values.push(srcs[i]);
                    }
                    this.value = values.join('|');

                    var new_arr = [];
                    for(var i=0;i<values.length;i++) {
                        var items=values[i];
                        //判断元素是否存在于new_arr中，如果不存在则插入到new_arr的最后
                        if($.inArray(items,new_arr)==-1) {
                            new_arr.push(items);
                        }
                    }

                    values = new_arr;

                    for (var i in values) {
                        //此行代码是点击放大图片  -- 去掉
                        var $tpl = $(tpl).attr('data-tips-image', values[i]).css('backgroundImage', 'url(' + values[i] + ')');
                        $tpl.data('input', input).data('srcs', values).data('index', i);
                        $tpl.on('click', 'a', function (e) {
                            e.stopPropagation();
                            var $cur = $(this).parent();
                            $.msg.confirm('确定要移除这张图片吗？', function () {
                                var data = $cur.data('srcs');
                                delete data[$cur.data('index')];
                                $cur.data('input').value = data.join('|');
                                $cur.remove();
                            });
                        });
                        $(this).before($tpl);
                    }
                });
            });
        </script>
    </div>
    <!--商品 轮播图-->


    <div class="layui-form-item">
        <label class="layui-form-label">商品详情</label>
        <div class="layui-input-block">
            <textarea name="detail" required="required"></textarea>
            <script type="text/javascript">
            require(['ckeditor'], function () {
                var editor = window.createEditor('[name="detail"]');
                // 设置内容
                // editor.setData('修改内容');
                // 获取内容
                var content = editor.getData();
                console.log(content);
            });
            </script>
            <script>
                layui.use('code', function () {
                    layui.code({encode: true});
                });
            </script>
        </div>
    </div>

    <div class="hr-line-dashed"></div>
    <div class="col-sm-4 col-sm-offset-2">
        {if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'/>{/if}
        <div class="layui-form-item text-center">
            <button class="layui-btn" type="submit">保存</button>
        </div>
    </div>
    <script type="text/javascript">
    layui.use('form', function(){
        var form = layui.form;      //只有执行了这一步，部分表单元素才会自动修饰成功
        form.render();
    });
    function tianjia(){
        var ht = '<div class="layui-form-item"><div class="layui-inline"><label class="layui-form-label">属性</label><div class="layui-input-inline"><select name="spec_id[]" lay-verify="required" lay-search>{volist name="spec" id="v1"}<option value="{$v1.id}" >{$v1.name}</option>{/volist}</select></div><div class="layui-input-inline" style="width: 100px;"><input type="text" name="details[]" required="required" placeholder="请输入属性名称" autocomplete="off" class="layui-input"></div><button onclick="reduce(this)">-</button></div>';
        var html = ht;
        // var html = '<div class="layui-form-item">'+ht+'</div>';
        // alert(html);
        $("#add").before(html);
        window.form.render('select'); //刷新select选择框渲染
    }
    function reduce(obj){
        $(obj).parent().remove();
    }

    form.on('select(test)', function(data){

    });

    form.verify({
        price: function(value, item){ //value：表单的值、item：表单的DOM对象
//            if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
//                return '用户名不能有特殊字符';
//            }
//            if(/(^\_)|(\__)|(\_+$)/.test(value)){
//                return '用户名首尾不能出现下划线\'_\'';
//            }
//            if(/^\d+\d+\d$/.test(value)){
//                return '用户名不能全为数字';
//            }
            if(test(value)<100){
                return '必须大于100';
            }
        }

    });

</script>
</form>

{/block}
